﻿<#
    本脚本的作用是 定时删除指定目录下的文件夹, 条件是
        1. 文件夹名称长度为34
        2. 文件夹名以AA开头
        3. 文件夹最后一次操作时间为3天前
#>

$now = [DateTime]::Now;

$folderFullPathWillOperate = "F:\CHUZHOUBDCDJ\apache-tomcat-7.0.56\webapps\ROOT\AffixFiles";

$foldersNeedDelete = Get-ChildItem -Path $folderFullPathWillOperate | ?{$_.GetType().Name.Equals("DirectoryInfo")} |?{$_.Name.Length -eq 34} | ?{$_.Name.StartsWith("AA")}| ?{($now - $_.LastWriteTime ).Days -gt 3};

cd $folderFullPathWillOperate;
foreach ($item in $foldersNeedDelete)
{
    Write-Host "remove directionary :",$item;
    Remove-Item $item -Force -Recurse
}

Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////";
Write-Host "the count of items which removed", $foldersNeedDelete.Length;